package com.lee.lease.web.admin.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lee.lease.model.entity.*;
import com.lee.lease.web.admin.mapper.*;
import com.lee.lease.web.admin.service.LeaseAgreementService;
import com.lee.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.lee.lease.web.admin.vo.agreement.AgreementVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author liubo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {
    @Autowired
    private LeaseAgreementMapper mapper;
    @Autowired
    private ApartmentInfoMapper apartmentInfoMapper;
    @Autowired
    private RoomInfoMapper roomInfoMapper;
    @Autowired
    private PaymentTypeMapper paymentTypeMapper;
    @Autowired
    private LeaseTermMapper leaseTermMapper;

    @Override
    public AgreementVo findById(Long id) {
        LeaseAgreement leaseAgreement = mapper.selectById(id);
        if (leaseAgreement == null) {
            return null;
        }
        AgreementVo agreementVo = new AgreementVo();
        BeanUtils.copyProperties(leaseAgreement,agreementVo);

        //查询属性
        ApartmentInfo apartmentInfo = apartmentInfoMapper.selectByAgreementId(id);
        RoomInfo roomInfo = roomInfoMapper.selectByAgreementId(id);
        PaymentType paymentType = paymentTypeMapper.selectByAgreementId(id);
        LeaseTerm leaseTerm = leaseTermMapper.selectByAgreementId(id);

        //设置属性
        agreementVo.setApartmentInfo(apartmentInfo);
        agreementVo.setRoomInfo(roomInfo);
        agreementVo.setPaymentType(paymentType);
        agreementVo.setLeaseTerm(leaseTerm);

        return agreementVo;
    }

    @Override
    public IPage<AgreementVo> selectByPage(IPage page, AgreementQueryVo queryVo) {
        return mapper.selectByQueryVo(page,queryVo);
    }
}




